﻿using System.Runtime.Serialization.Formatters.Binary;
using System.IO;

class Ex2StudentSerialization
{
    static void Main()
    {
        WriteStudentToFile(new Student("Petur", "Subev", 123123));
    }

    public static void WriteStudentToFile(Student studentToWrite)
    {
        BinaryFormatter formatter = new BinaryFormatter();
        using (FileStream mStream = new FileStream("studentFile.bin", FileMode.Append))
        {
            formatter.Serialize(mStream, studentToWrite);
        }
        using (FileStream mStream = new FileStream("studentFile.bin", FileMode.Open))
        {
            Student revived = formatter.Deserialize(mStream) as Student;
            System.Console.WriteLine("{0} {1} {2}", revived.FirstName, revived.LastName, revived.FacultyNumber);
        }
    }
}